class Solution:
    def preimageSizeFZF(self, k: int) -> int:
        lst = [1]
        while lst[-1] < k:
            lst.append(lst[-1] * 5 + 1)

        while k > 0 and len(lst) > 1:
            k %= lst.pop()
            if k >= lst[-1] * 5:
                return 0

        return 5


if __name__ == "__main__":
    print(Solution().preimageSizeFZF(0))  # 5
    print(Solution().preimageSizeFZF(5))  # 0
